/**
 * @(#)TestChannel3.java, Nov 21, 2012. 
 * 
 * Copyright 2012 Yodao, Inc. All rights reserved.
 * YODAO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.buaaer.net;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;


/**
 *
 * @author wangheng
 *
 */
public class TestChannel3 {


    public static void main(String[] args) throws Exception {
        
        InetSocketAddress addr = new InetSocketAddress("localhost", 12345);
        SocketChannel channel = SocketChannel.open(addr);
        channel.configureBlocking(false);
        
        WritableByteChannel out = Channels.newChannel(System.out);
        ByteBuffer buf = ByteBuffer.allocate(50);
        
        while(channel.read(buf) != -1) {
            buf.flip();
            out.write(buf);
            buf.clear();
        }
            


       
        
        
    }

}
